package com.dotflat.fin.controller;

import com.dotflat.fin.PO.FinPlanPO;
import com.dotflat.fin.PO.ProductSolutionPO;
import com.dotflat.fin.domain.FinPlan;
import com.dotflat.fin.domain.ProductSolution;
import com.dotflat.fin.dto.ProductSolutionListDTO;
import com.dotflat.fin.service.FinPlanService;
import com.dotflat.fin.service.ProductSolutionService;
import com.dotflat.rest.controller.RestfulBaseController;
import com.matt.commons.dto.sso.StaffDTO;
import com.matt.commons.model.StatusResponse;
import com.matt.commons.page.PagerQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import static com.matt.foundation.constant.CommonConstant.TICKET;
import static org.springframework.data.domain.Sort.Direction.DESC;


/**
 * @author ：Ron
 * @date ：Created in 11/6/2020 5:07 PM
 */
@RestController
@RequestMapping("/fin/product_solution")
@Slf4j
@Api(tags = "财务 - 收费设置 - 收费方案")
public class ProductSolutionController extends RestfulBaseController<ProductSolution, ProductSolutionService, ProductSolutionPO> {

    @Autowired
    public void setBaseService(ProductSolutionService service){
        this.baseService = service;
    }

    @ApiOperation(value = "获取列表", response = ProductSolutionListDTO.class)
    @GetMapping("/list")
    @Override
    public StatusResponse getList(@RequestHeader(TICKET) String ticket, ProductSolutionPO param, PagerQuery pagerQuery){

        StatusResponse result = super.getList(ticket, param, pagerQuery);

        if (result.getData() == null){
            return result;
        }

        Page<ProductSolution> solutions = (Page<ProductSolution>) result.getData();

        Page<ProductSolutionListDTO> ret = solutions.map(o->ProductSolutionListDTO.of(o));

        return StatusResponse.of(result.getCode(), result.getMsg(), ret);
    }

}
